var t = require("../../../../@babel/runtime/helpers/regeneratorRuntime"), i = require("../../../../@babel/runtime/helpers/asyncToGenerator"), e = require("../../../../common/vendor.js"), s = require("../../../uv-ui-tools/libs/mixin/mpMixin.js"), n = require("../../../uv-ui-tools/libs/mixin/mixin.js"), o = require("./props.js");

require("../../../uv-ui-tools/libs/function/index.js"), require("../../../uv-ui-tools/libs/function/test.js"), 
require("../../../uv-ui-tools/libs/function/digit.js"), require("../../../uv-ui-tools/libs/util/route.js"), 
require("../../../uv-ui-tools/libs/function/debounce.js"), require("../../../uv-ui-tools/libs/function/throttle.js");

var r = {
    name: "uv-sticky",
    mixins: [ s.mpMixin, n.mixin, o.props ],
    data: function() {
        return {
            cssSticky: !1,
            stickyTop: 0,
            elId: "",
            left: 0,
            width: "auto",
            height: "auto",
            fixed: !1
        };
    },
    computed: {
        style: function() {
            var t = {};
            return this.disabled ? t.position = "static" : this.cssSticky ? (t.position = "sticky", 
            t.zIndex = this.uZindex, t.top = this.$uv.addUnit(this.stickyTop)) : t.height = this.fixed ? this.height + "px" : "auto", 
            t.backgroundColor = this.bgColor, this.$uv.deepMerge(t, this.$uv.addStyle(this.customStyle));
        },
        stickyContent: function() {
            var t = {};
            return this.cssSticky || (t.position = this.fixed ? "fixed" : "static", t.top = this.stickyTop + "px", 
            t.left = this.left + "px", t.width = "auto" == this.width ? "auto" : this.width + "px", 
            t.zIndex = this.uZindex), t;
        },
        uZindex: function() {
            return this.zIndex ? this.zIndex : 970;
        }
    },
    created: function() {
        this.elId = this.$uv.guid();
    },
    mounted: function() {
        this.init();
    },
    methods: {
        init: function() {
            this.getStickyTop(), this.checkSupportCssSticky(), this.cssSticky || !this.disabled && this.initObserveContent();
        },
        initObserveContent: function() {
            var t = this;
            this.$uvGetRect("#" + this.elId).then(function(i) {
                t.height = i.height, t.left = i.left, t.width = i.width, t.$nextTick(function() {
                    t.observeContent();
                });
            });
        },
        observeContent: function() {
            var t = this;
            this.disconnectObserver("contentObserver");
            var i = e.index.createIntersectionObserver({
                thresholds: [ .95, .98, 1 ]
            });
            i.relativeToViewport({
                top: -this.stickyTop
            }), i.observe("#".concat(this.elId), function(i) {
                t.setFixed(i.boundingClientRect.top);
            }), this.contentObserver = i;
        },
        setFixed: function(t) {
            var i = t <= this.stickyTop;
            this.fixed = i;
        },
        disconnectObserver: function(t) {
            var i = this[t];
            i && i.disconnect();
        },
        getStickyTop: function() {
            this.stickyTop = this.$uv.getPx(this.offsetTop) + this.$uv.getPx(this.customNavHeight);
        },
        checkSupportCssSticky: function() {
            var e = this;
            return i(t().mark(function i() {
                return t().wrap(function(t) {
                    for (;;) switch (t.prev = t.next) {
                      case 0:
                        return "android" === e.$uv.os() && Number(e.$uv.sys().system) > 8 && (e.cssSticky = !0), 
                        t.next = 3, e.checkComputedStyle();

                      case 3:
                        e.cssSticky = t.sent, "ios" === e.$uv.os() && (e.cssSticky = !0);

                      case 5:
                      case "end":
                        return t.stop();
                    }
                }, i);
            }))();
        },
        checkComputedStyle: function() {
            var t = this;
            return new Promise(function(i) {
                e.index.createSelectorQuery().in(t).select(".uv-sticky").fields({
                    computedStyle: [ "position" ]
                }).exec(function(t) {
                    i("sticky" === t[0].position);
                });
            });
        },
        checkCssStickyForH5: function() {}
    },
    unmounted: function() {
        this.disconnectObserver("contentObserver");
    }
}, c = e._export_sfc(r, [ [ "render", function(t, i, s, n, o, r) {
    return {
        a: e.s(r.stickyContent),
        b: o.elId,
        c: e.s(r.style)
    };
} ], [ "__scopeId", "data-v-b87ae031" ] ]);

wx.createComponent(c);